//
//  ContentCollectionViewCell.m
//  礼物说
//
//  Created by dllo on 16/4/22.
//  Copyright © 2016年 sunzhichao. All rights reserved.
//

#import "ContentCollectionViewCell.h"

#define KIMG [UIImage imageNamed:@"LIKE_66.731707317073px_1179710_easyicon.net.png"];

@interface ContentCollectionViewCell ()

@property (nonatomic, retain) BaseView *view;
@property (nonatomic, retain) BaseImageView *imgView;

@property (nonatomic, retain) BaseView *likeButtom;
@property (nonatomic, retain) BaseImageView *likeImgView;
@property (nonatomic, retain) BaseLabel *likeLable;
@property (nonatomic, retain) BaseView *likeView;

@end

@implementation ContentCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createCell];
    }
    return self;
}
- (void)dealloc {
    [_titleLable release];
    [_likeView release];
    [_model release];
    [_view release];
    [_imgView release];
    [_likeLable release];
    [_likeImgView release];
    [_likeButtom release];
    [super dealloc];
}

- (void)setModel:(ContentModel *)model {
    if (_model != model) {
        [_model release];
        _model = [model retain];
        [self.imgView sd_setImageWithURL:[NSURL URLWithString:_model.cover_image_url] placeholderImage:[UIImage imageNamed:@"placeholder@2x副本.png"]];
        self.titleLable.text = _model.title;
        self.likeLable.text =[_model.likes_count stringValue];
    }
}

- (void)setGongLvContentModel:(GongLvContentModel *)gongLvContentModel {
    if (_gongLvContentModel != gongLvContentModel) {
        [_gongLvContentModel release];
        _gongLvContentModel = [gongLvContentModel retain];
    }
    [self.imgView sd_setImageWithURL:[NSURL URLWithString:_gongLvContentModel.cover_image_url] placeholderImage:[UIImage imageNamed:@"placeholder@2x副本.png"]];
    self.titleLable.text = _gongLvContentModel.title;
    self.likeLable.text = [_gongLvContentModel.likes_count stringValue];
}

- (void)createCell {
    /** 底部白的view*/
    self.view = [[BaseView alloc] init];
    [self.contentView addSubview:_view];
    [_view release];
    
    /** 图片*/
    self.imgView = [[BaseImageView alloc] init];
    [self.contentView addSubview:_imgView];
    [_imgView release];
    
    /** 喜欢Lable底部的View*/
    self.likeView = [[BaseView alloc] init];
    [self.contentView addSubview:_likeView];
    [_likeView release];
    
    /** 标题*/
    self.titleLable = [[BaseLabel alloc] init];
    [self.contentView addSubview:_titleLable];
    [_titleLable release];
    
    /** 喜欢灰色view*/
    self.likeButtom = [[BaseView alloc] init];
    [self.contentView addSubview:_likeButtom];
    [_likeButtom release];
    
    /** ❤️型*/
    self.likeImgView = [[BaseImageView alloc] init];
    [self.contentView addSubview:_likeImgView];
    [_likeImgView release];
    
    /** 喜欢额人数*/
    self.likeLable = [[BaseLabel alloc] init];
    [self.contentView addSubview:_likeLable];
    [_likeLable release];
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
    [super layoutSubviews];
    
    _view.frame = self.contentView.frame;
    
    _imgView.frame = CGRectMake(kWIDTHS(5), kHEIGHTS(5), kWIDTHCELL - 10, kHEIGHTCELL - 10);
    
    _likeView.frame = CGRectMake(kWIDTHS(5), kHEIGHTCELL - 45, kWIDTHCELL - 10, kWIDTHS(40));
    _likeView.backgroundColor = [UIColor grayColor];
    /** 改变透明度*/
    _likeView.alpha = .5;
    
    _titleLable.frame = CGRectMake(kWIDTHS(10), kHEIGHTCELL - 50, kWIDTHCELL - 20, kWIDTHS(40));
    /** 字体颜色*/
    _titleLable.textColor = [UIColor whiteColor];
    _titleLable.numberOfLines = 2;
    
    _likeButtom.frame = CGRectMake(kWIDTHCELL - kWIDTHS(65), kHEIGHTS(5), kWIDTHS(50), kHEIGHTS(60));
    _likeButtom.backgroundColor = [UIColor blackColor];
    _likeButtom.alpha = .45;
    
    _likeImgView.frame = CGRectMake(kWIDTHCELL - kWIDTHS(65) , kWIDTHS(5), kWIDTHS(50), kHEIGHTS(40));
    _likeImgView.image = KIMG;
    
    _likeLable.frame = CGRectMake(kWIDTHCELL - kWIDTHS(65), kWIDTHS(45), kWIDTHS(50), kHEIGHTS(20));
    _likeLable.textColor = [UIColor whiteColor];
    _likeLable.font = [UIFont systemFontOfSize: 13.0];
    _likeLable.numberOfLines = 2;
}

@end
